package com.obligatorio.domain.convertidores;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import org.apache.log4j.Logger;

import com.obligatorio.domain.Pais;


//@FacesConverter(forClass = Pais.class)
public class PaisConverter implements Converter {
	private static final Logger log = Logger.getLogger(PaisConverter.class
			.getName());

	@Override
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
		log.info("getAsObject()");
		try {

//			HttpSession session = (HttpSession) FacesContext
//					.getCurrentInstance().getExternalContext()
//					.getSession(false);
//			Usuario tmpUsr = (Usuario) session.getAttribute("user");
//			Pais objPais = new Pais(arg2);
//			tmpUsr.setPais(objPais);
//
//			session.setAttribute("user", tmpUsr);

			 Pais objPais = new Pais(arg2);
			 log.info(objPais.toString());
			 return objPais;
		} catch (Exception e) {
			log.error(e);
			e.printStackTrace();
		}

		return null;
	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
		// TODO Auto-generated method stub
		return null;
	}

}
